﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace XRPGLibrary.Controls
{
    public abstract class Control
    {
        #region Field Region
        protected string name;//控件的名称
        protected string text;//控件表面绘制的字符
        protected Vector2 size;//控件的大小
        protected Vector2 position;//控件在窗体上的位置
        protected object value;//可以为控件设置一个抽象的值
        protected bool hasFocus;//是否被选定
        protected bool enabled;//是否可用
        protected bool visible;//是否可见
        protected bool tabStop;//
        protected SpriteFont spriteFont;//SpriteFont对象，用来存储spritefont资源
        protected Color color;//控件的颜色
        protected string type;//控件的所属类型
        #endregion
        #region Event Region//控件选中事件
        public event EventHandler Selected;
        #endregion
        #region Property Region//属性的对外接口
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        public string Text
        {
            get { return text; }
            set { text = value; }
        }
        public Vector2 Size
        {
            get { return size; }
            set { size = value; }
        }
        public Vector2 Position
        {
            get { return position; }
            set
            {
                position = value;
                position.Y = (int)position.Y;
            }
        }
        public object Value
        {
            get { return value; }
            set { this.value = value; }
        }
        public bool HasFocus
        {
            get { return hasFocus; }
            set { hasFocus = value; }
        }
        public bool Enabled
        {
            get { return enabled; }
            set { enabled = value; }
        }
        public bool Visible
        {
            get { return visible; }
            set { visible = value; }
        }
        public bool TabStop
        {
            get { return tabStop; }
            set { tabStop = value; }
        }
        public SpriteFont SpriteFont
        {
            get { return spriteFont; }
            set { spriteFont = value; }
        }
        public Color Color
        {
            get { return color; }
            set { color = value; }
        }
        public string Type
        {
            get { return type; }
            set { type = value; }
        }
        #endregion
        #region Constructor Region构造函数
        public Control()
        {
            Color = Color.White;
            Enabled = true;
            Visible = true;
            SpriteFont = ControlManager.SpriteFont;
        }
        #endregion
        #region Abstract Methods控件的方法，继承该基类的控件类要在类体内实现
        public abstract void Update(GameTime gameTime);//更新方法
        public abstract void Draw(SpriteBatch spriteBatch);//绘制方法
        public abstract void HandleInput(PlayerIndex playerIndex);//输入方法
        #endregion
        #region Virtual Methods//触发选中事件
        protected virtual void OnSelected(EventArgs e)
        {
            if (Selected != null)
            {
                Selected(this, e);
            }
        }
        #endregion
    }
}